package com.jinghao.tws.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.jinghao.core.common.exception.JingHaoCustomerException;
import com.jinghao.core.common.service.impl.JingHaoBaseServiceImpl;
import com.jinghao.core.common.util.JingHaoPageInfo;
import com.jinghao.core.common.util.cnd.IJhSql.ORDER;
import com.jinghao.core.common.util.cnd.JhCnd;
import com.jinghao.core.common.util.cnd.JhUpdate;
import com.jinghao.tws.entity.WvAccessConfig;
import com.jinghao.tws.entity.WvAutoUploadCloudConfig;
import com.jinghao.tws.entity.WvFlow;
import com.jinghao.tws.entity.WvFlow.EWvFlow;
import com.jinghao.tws.entity.WvPallet;
import com.jinghao.tws.entity.WvPallet.EWvPallet;
import com.jinghao.tws.entity.WvProcess;
import com.jinghao.tws.entity.WvProcess.EWvProcess;
import com.jinghao.tws.entity.WvProduct;
import com.jinghao.tws.entity.WvProduct.EWvProduct;
import com.jinghao.tws.entity.WvTaskInfo;
import com.jinghao.tws.entity.WvTaskInfo.EWvTaskInfo;
import com.jinghao.tws.entity.WvUploadTaskInfo;
import com.jinghao.tws.entity.WvUploadTaskInfo.EWvUploadTaskInfo;
import com.jinghao.tws.service.IWvAccessConfigService;
import com.jinghao.tws.service.IWvAutoUploadCloudConfigService;
import com.jinghao.tws.service.IWvFlowService;
import com.jinghao.tws.service.IWvPalletService;
import com.jinghao.tws.service.IWvProcessMergeConfigService;
import com.jinghao.tws.service.IWvProcessService;
import com.jinghao.tws.service.IWvProductService;
import com.jinghao.tws.service.IWvPublicSynchronousService;
import com.jinghao.tws.service.IWvTaskInfoService;
import com.jinghao.tws.service.IWvUploadTaskInfoService;
import com.jinghao.tws.util.EJhTwsCode;

@Service("wvTaskInfoService")
public class WvTaskInfoServiceImpl extends JingHaoBaseServiceImpl<WvTaskInfo> implements IWvTaskInfoService {
	//==================定制内容开始======================
	
	@Resource
	private IWvFlowService wvFlowService;
	
	@Resource
	private IWvProductService wvProductService;
	
	@Resource
	private IWvProcessService wvProcessService;
	
	@Resource
	private IWvPalletService wvPalletService;
	
	@Resource
	private IWvAccessConfigService wvAccessConfigService;
	
	@Resource
	private IWvUploadTaskInfoService wvUploadTaskInfoService;
	
	@Resource
	private IWvProcessMergeConfigService wvProcessMergeConfigService;
	
	@Resource
	private IWvPublicSynchronousService  wvPublicSynchronousService;
	
	@Resource
	private IWvAutoUploadCloudConfigService  wvAutoUploadCloudConfigService;
	
	
//在这里修改代码
	@Override
	public void listWvTaskInfo(WvTaskInfo model) {
		JhCnd cnd=new JhCnd();
		if (StringUtils.isEmpty(model.getFpalletId())) {
			//throw new JingHaoCustomerException(EJhTwsCode.TWS8001.getCode(),"托盘编号不能为空，请重新输入！");
			cnd.append("1=1");
		}else{
			cnd.andEquals("fpalletId");
		}
	    cnd.orderBy("createTime", ORDER.DESC);
	     
		model.setJhCnd(cnd);
	    List<Map<String,Object>> list=this.queryMapListById(model,"listMapListByfpalletId");
	    model.setMapList(list);
	}

	@Override
	public void deleteTaskInfo(WvTaskInfo model) {
		if (null==model.getStrList()||model.getStrList().size()<=0) {
			throw new JingHaoCustomerException(EJhTwsCode.TWS8001.getCode(),"请至少选择一条记录进行删除，请重新进行选择！");
		}
		JhCnd cnd=new JhCnd();
	    cnd.andIn("taskUuid", "strList", model.getStrList());
	    model.setJhCnd(cnd);
	    this.deleteSame(model);
	}

	
	@Override
	public void updateTaskInfo(WvTaskInfo model) {
		if (null==model.getStrList()||model.getStrList().size()<=0) {
			throw new JingHaoCustomerException(EJhTwsCode.TWS8001.getCode(),"请至少选择一条记录进行操作，请重新进行选择！");
		}
		JhCnd cnd=new JhCnd();
	    cnd.andIn("taskUuid", "strList", model.getStrList());
	    model.setJhCnd(cnd);
	    model.setVideoStatus(EWvTaskInfo.videoStatus_1.getKey());
	    JhUpdate update=new JhUpdate();
	    update.add("videoStatus");
	    model.setUpdateSet(update);
	    this.updateSame(model);
		
	}
	public void updateTimingErrorTask() {
		//JingHaoPageInfo page=new JingHaoPageInfo();
		//page.setLimit(300);
		WvTaskInfo model=new WvTaskInfo();
		List<Integer> statusList=new ArrayList<Integer>();
		statusList.add(EWvTaskInfo.videoStatus_1.getKey());
		statusList.add(EWvTaskInfo.videoStatus_2.getKey());
		model.setIntList(statusList);
		JhCnd cnd=new JhCnd();
		//cnd.andIn("videoStatus", "intList", statusList);
		cnd.append(" 1=1 and (video_Status=9 and TIMESTAMPDIFF(MINUTE,FIRST_ERROR_TIME,LAST_CHECK_TIME)<=1440) ");
		cnd.orderBy("last_Check_Time", "asc");
		model.setJhCnd(cnd);
		model.setPage(null);
		List<WvTaskInfo> list=this.queryModelList(model);
		
		if(list==null||list.size()<=0){
			return ;
		}
		this.updateTimingTaskInfo(model,list);
		list.clear();
		list=null;
	}
	
	
	@Override
	public void updateTimingCheckTask() {
		JingHaoPageInfo page=new JingHaoPageInfo();
		page.setLimit(30);
		WvTaskInfo model=new WvTaskInfo();
		List<Integer> statusList=new ArrayList<Integer>();
		statusList.add(EWvTaskInfo.videoStatus_1.getKey());
		statusList.add(EWvTaskInfo.videoStatus_2.getKey());
		model.setIntList(statusList);
		JhCnd cnd=new JhCnd();
		cnd.append(" 1=1 and video_Status in (2) ");
		cnd.orderBy("create_Time", "asc");
		model.setJhCnd(cnd);
		model.setPage(page);
		List<WvTaskInfo> list=this.queryModelList(model);
		
		if(list==null||list.size()<=0){
			return ;
		}
		this.updateTimingTaskInfo(model,list);
		list.clear();
		list=null;
		
	}

	public void updateTimingTask() {
		JingHaoPageInfo page=new JingHaoPageInfo();
		page.setLimit(5);
		WvTaskInfo model=new WvTaskInfo();
		List<Integer> statusList=new ArrayList<Integer>();
		statusList.add(EWvTaskInfo.videoStatus_1.getKey());
		statusList.add(EWvTaskInfo.videoStatus_2.getKey());
		model.setIntList(statusList);
		JhCnd cnd=new JhCnd();
		cnd.append(" 1=1 and video_Status in (1) ");
		cnd.orderBy("create_Time", "asc");
		model.setJhCnd(cnd);
		model.setPage(page);
		List<WvTaskInfo> list=this.queryModelList(model);
		
		if(list==null||list.size()<=0){
			return ;
		}
		this.updateTimingTaskInfo(model,list);
		list.clear();
		list=null;
	}
	  
	public void updateTimingTaskInfo(WvTaskInfo model,List<WvTaskInfo> list) {
		JhCnd cnd=new JhCnd();
		cnd.reset();
		if(list==null||list.size()<=0){
			return ;
		}
		WvAccessConfig wvAccessConfig=this.wvAccessConfigService.getWvAccessConfigInfo();
		String userName=wvAccessConfig.getUsername();
		String password=wvAccessConfig.getPassword();
		String dtUrl=wvAccessConfig.getBucket();
		String httpUrl=wvAccessConfig.getAddress();
		if(httpUrl.substring(httpUrl.length()-1, httpUrl.length()).equals("/")){
			httpUrl=wvAccessConfig.getAddress()+""+dtUrl;
		}else{
			httpUrl=wvAccessConfig.getAddress()+"/"+dtUrl;
		}
		//第一步：登录 
		String sessionKey=this.wvAccessConfigService.vmsLogin(userName,password,httpUrl);
		
		
		String mediaInfo="",concatenateRequestId=null;
		Map<String,Object> resultMap=null,fileMap=null,videoMap=null;;
		int isSuccess=0;//视频是否生成开关
		String url=null;
		WvProduct wvProduct=null;
		WvProcess wvProcess=null;
		WvPallet wvPallet=null;
		JhUpdate updateSet=null;
		int type;
		WvUploadTaskInfo wvTaskInfo=null;
		for(WvTaskInfo wvTask:list){
			isSuccess=0;
			url=null;
			//第二步：根据视频信息生成唯一码
			if(wvTask.getMedioInfo()!=null){
				mediaInfo=wvTask.getMedioInfo();
				concatenateRequestId=wvTask.getRequestId();
				//视频生成逻辑 
				//1、当第一次生成视频时，执行视频生成逻辑。
				//2、当视频生成错误时，30分钟后，重新执行视频生成逻辑，当超过24小时则不再执行该逻辑。
				//3、当视频生成中时，每5秒执行视频check逻辑。 
				if(wvTask.getVideoStatus().equals(EWvTaskInfo.videoStatus_1.getKey())||wvTask.getVideoStatus().equals(EWvTaskInfo.videoStatus_9.getKey())){
					videoMap=this.wvAccessConfigService.vmsRequestconcatenatevideo(httpUrl,sessionKey,mediaInfo);
					if(videoMap.get("result")!=null&&videoMap.get("result").toString().equals("ok")){
						concatenateRequestId=videoMap.get("concatenate-request-id").toString();
			        }else{
			        		concatenateRequestId=null;
			        }
				}else if(wvTask.getVideoStatus().equals(EWvTaskInfo.videoStatus_2.getKey())){
					if(concatenateRequestId==null||concatenateRequestId.trim().equals("")){
						videoMap=this.wvAccessConfigService.vmsRequestconcatenatevideo(httpUrl,sessionKey,mediaInfo);
						if(videoMap.get("result")!=null&&videoMap.get("result").toString().equals("ok")){
							concatenateRequestId=videoMap.get("concatenate-request-id").toString();
						}else{
							concatenateRequestId=null;
						}
					}
				}else{
					concatenateRequestId=null;
				}
				wvTask.setRequestId(concatenateRequestId);
				if(concatenateRequestId!=null&&!concatenateRequestId.trim().equals("")){
					//第三步：获取视频生成状态
					resultMap=this.wvAccessConfigService.vmsCheckconcatenatevideostatus(httpUrl,sessionKey, concatenateRequestId);
					if(resultMap!=null&&resultMap.get("result")!=null&&resultMap.get("result").toString().equals("ok")){
						if(resultMap.get("status")!=null&&resultMap.get("status").toString().equals("COMPLETED")){
							if(resultMap.get("file")!=null){
								fileMap=(Map<String,Object>)resultMap.get("file");
								if(fileMap.get("url")!=null){
									isSuccess=2;
									url=fileMap.get("url").toString();
								}else{
									wvTask.setVideoStatus(EWvTaskInfo.videoStatus_9.getKey());
									wvTask.setErrorInfo(JSON.toJSONString(resultMap));
									//未知错误信息
									this.logger.info("自动生成视频异常信息（checkconcatenatevideostatus）：时间："+new Date()+",result:"+JSON.toJSONString(resultMap));
								}
							}else{
								wvTask.setVideoStatus(EWvTaskInfo.videoStatus_9.getKey());
								wvTask.setErrorInfo(JSON.toJSONString(resultMap));
								//未知错误信息
								this.logger.info("自动生成视频异常信息（checkconcatenatevideostatus）：时间："+new Date()+",result:"+JSON.toJSONString(resultMap));
							}
							
						}else if(resultMap.get("status")!=null&&resultMap.get("status").toString().equals("IN_PROGRESS")){
							if(resultMap.get("progress")!=null){
								isSuccess=1;
								wvTask.setProgress(Integer.parseInt(resultMap.get("progress").toString()));
								wvTask.setVideoStatus(EWvTaskInfo.videoStatus_2.getKey());
							}else{
								wvTask.setVideoStatus(EWvTaskInfo.videoStatus_9.getKey());
								wvTask.setErrorInfo(JSON.toJSONString(resultMap));
								//未知错误信息
								this.logger.info("自动生成视频异常信息（checkconcatenatevideostatus）：时间："+new Date()+",result:"+JSON.toJSONString(resultMap));
							}
						}else{
							wvTask.setVideoStatus(EWvTaskInfo.videoStatus_9.getKey());
							wvTask.setErrorInfo(JSON.toJSONString(resultMap));
							//未知错误信息
							this.logger.info("自动生成视频异常信息（checkconcatenatevideostatus）：时间："+new Date()+",result:"+JSON.toJSONString(resultMap));
						}
					}else if(resultMap!=null&&resultMap.get("result")!=null&&resultMap.get("result").toString().equals("error")){
						wvTask.setVideoStatus(EWvTaskInfo.videoStatus_9.getKey());
						wvTask.setErrorInfo(JSON.toJSONString(resultMap));
					}else{
						wvTask.setVideoStatus(EWvTaskInfo.videoStatus_9.getKey());
						wvTask.setErrorInfo(JSON.toJSONString(resultMap));
						//未知错误信息
						this.logger.info("自动生成视频异常信息（checkconcatenatevideostatus）：时间："+new Date()+",result:"+JSON.toJSONString(resultMap));
					}
				}else{
					wvTask.setVideoStatus(EWvTaskInfo.videoStatus_9.getKey());
					wvTask.setErrorInfo(JSON.toJSONString(videoMap));
		        		this.logger.info("自动生成视频异常信息（vmsRequestconcatenatevideo）：时间："+new Date()+",mediaInfo:"+mediaInfo+",result:"+JSON.toJSONString(videoMap));
				}
				//第四步：更新任务信息表
				if(isSuccess==0){//生成失败
					cnd.reset();
					cnd.andEquals("taskUuid");
					updateSet=new JhUpdate();
					wvTask.setLastCheckTime(new Date());
					updateSet.add("videoStatus").add("errorInfo").add("lastCheckTime").add("requestId");
					if(null==wvTask.getFirstErrorTime()){
						wvTask.setFirstErrorTime(new Date());
						updateSet.add("firstErrorTime");
					}
					wvTask.setUpdateSet(updateSet);
					wvTask.setJhCnd(cnd);
					this.updateSame(wvTask);
				}else if(isSuccess==1){ //生成中
					cnd.reset();
					cnd.andEquals("taskUuid");
					updateSet=new JhUpdate();
					wvTask.setLastCheckTime(new Date());
					updateSet.add("videoStatus").add("progress").add("lastCheckTime").add("requestId");
					wvTask.setUpdateSet(updateSet);
					wvTask.setJhCnd(cnd);
					this.updateSame(wvTask);
				}else if(isSuccess==2){//生成成功
					cnd.reset();
					//第五步：更新视频信息
					type=wvTask.getType();
					updateSet=new JhUpdate();
					if(type==EWvTaskInfo.type_1.getKey()){
						//环节视频
						wvProcess=new WvProcess();
						wvProcess.setProcessUuid(wvTask.getFprocessUuid());
						wvProcess.setUrlLink(url);
						wvProcess.setUrlStatus(EWvProcess.urlStatus_1.getKey());
						wvProcess.setFileUploadStatus(EWvPallet.fileUploadStatus_1.getKey());
						cnd.andEquals("processUuid");
						updateSet.add("urlStatus").add("urlLink").add("fileUploadStatus");
						wvProcess.setJhCnd(cnd);
						wvProcess.setUpdateSet(updateSet);
						this.wvProcessService.updateSame(wvProcess);
						
						//保存视频任务生成
						wvTaskInfo=new WvUploadTaskInfo();
						wvTaskInfo.setTaskUuid(model.getUUID());
						wvTaskInfo.setCreateTime(new Date());
						wvTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_6.getKey());
						wvTaskInfo.setWorkUuid(wvProcess.getProcessUuid());
						wvTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_6.getKey());
						
						cnd.reset();
						cnd.andEquals("workUuid");
						wvTaskInfo.setJhCnd(cnd);
						this.wvUploadTaskInfoService.deleteSame(wvTaskInfo);
						
						this.wvUploadTaskInfoService.add(wvTaskInfo);
						
					}else if(type==EWvTaskInfo.type_2.getKey()){
						//合并环节任务
						updateSet.add("urlStatus").add("urlLink").add("fileUploadStatus");
						wvPallet=new WvPallet();
						wvPallet.setPalletUuid(wvTask.getFpalletUuid());
						wvPallet.setUrlLink(url);
						wvPallet.setUrlStatus(EWvPallet.urlStatus_1.getKey());
						wvPallet.setFileUploadStatus(EWvPallet.fileUploadStatus_1.getKey());
						cnd.andEquals("palletUuid");
						wvPallet.setJhCnd(cnd);
						wvPallet.setUpdateSet(updateSet);
						this.wvPalletService.updateSame(wvPallet);
						
						//保存视频任务生成
						wvTaskInfo=new WvUploadTaskInfo();
						wvTaskInfo.setTaskUuid(model.getUUID());
						wvTaskInfo.setCreateTime(new Date());
						wvTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_7.getKey());
						wvTaskInfo.setWorkUuid(wvPallet.getPalletUuid());
						wvTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_7.getKey());
						
						cnd.reset();
						cnd.andEquals("workUuid");
						wvTaskInfo.setJhCnd(cnd);
						this.wvUploadTaskInfoService.deleteSame(wvTaskInfo);
						
						this.wvUploadTaskInfoService.add(wvTaskInfo);
					}else if(type==EWvTaskInfo.type_3.getKey()){
						//短损任务
						updateSet.add("urlStatus").add("urlLink").add("fileUploadStatus");
						wvProduct=new WvProduct();
						wvProduct.setProductUuid(wvTask.getFproductUuid());
						wvProduct.setUrlLink(url);
						wvProduct.setUrlStatus(EWvProduct.urlStatus_1.getKey());
						wvProduct.setFileUploadStatus(EWvProduct.fileUploadStatus_1.getKey());
						cnd.andEquals("productUuid");
						wvProduct.setJhCnd(cnd);
						wvProduct.setUpdateSet(updateSet);
						this.wvProductService.updateSame(wvProduct);
						
						//保存视频任务生成
						wvTaskInfo=new WvUploadTaskInfo();
						wvTaskInfo.setTaskUuid(model.getUUID());
						wvTaskInfo.setCreateTime(new Date());
						wvTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_8.getKey());
						wvTaskInfo.setWorkUuid(wvProduct.getProductUuid());
						wvTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_8.getKey());
						
						cnd.reset();
						cnd.andEquals("workUuid");
						wvTaskInfo.setJhCnd(cnd);
						this.wvUploadTaskInfoService.deleteSame(wvTaskInfo);
						
						this.wvUploadTaskInfoService.add(wvTaskInfo);
					}
					//删除任务信息 ,使用条件删除，有利于当任务不存在时，不会出现null异常
					//this.delete(wvTask);
					cnd.reset();
					cnd.andEquals("taskUuid");
					wvTask.setJhCnd(cnd);
					this.deleteSame(wvTask);
				}
			}
		}
		//消除数据
		list.clear();
		list=null;
		resultMap=null;
	}

	@Override
	public void updateCloudTaskInfo() {
		WvTaskInfo  model=new WvTaskInfo();
		List<String> uuidList=new ArrayList<String>();
		JhCnd cnd=new JhCnd();
		//第一步：查询托盘任务
		WvPallet  wvPallet=new  WvPallet();
		WvUploadTaskInfo wvUploadTaskInfo=null;
		List<Map<String,Object>> listWvPallet=null;
		JingHaoPageInfo page=new JingHaoPageInfo();
		page.setLimit(200);
		for(int i=0;i<5;i++){ 
			cnd.reset();
			cnd.andEquals("uploadStatus");
			wvPallet.setUploadStatus(EWvPallet.uploadStatus_1.getKey());
			cnd.append(" or (upload_Status=2 and pallet_uuid not in (select work_uuid from WV_UPLOAD_TASK_INFO where task_type=3)) ");
			wvPallet.setJhCnd(cnd);
			wvPallet.setPage(page);
			listWvPallet=this.wvPalletService.queryMapListById(wvPallet, "queryMapListToPalletUuid");
			if(listWvPallet!=null&&listWvPallet.size()>0){
				//A:保存任务信息
				 for(Map<String,Object> map:listWvPallet){
					 uuidList.add(map.get("palletUuid").toString());
					 wvUploadTaskInfo=new WvUploadTaskInfo();
					 wvUploadTaskInfo.setTaskUuid(model.getUUID());
					 wvUploadTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_3.getKey());
					 wvUploadTaskInfo.setCreateTime(new Date());
					 wvUploadTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_3.getKey());
					 wvUploadTaskInfo.setWorkUuid(map.get("palletUuid").toString());
					 this.wvUploadTaskInfoService.add(wvUploadTaskInfo);
				 }
				 wvPallet.setStrList(uuidList);
				 cnd.reset();
				 cnd.andIn("palletUuid", "strList", uuidList);
				 wvPallet.setUploadStatus(EWvProcess.uploadStatus_2.getKey());
				 JhUpdate jhUpdate=new JhUpdate();
				 jhUpdate.add("uploadStatus");
				 wvPallet.setJhCnd(cnd);
				 wvPallet.setJhUpdate(jhUpdate);
				 this.wvPalletService.updateSame(wvPallet);
				 uuidList.clear();
			}else{
				 break;
			}
		}
		
		//第二步：查询环节信息任务
		WvProcess wvProcess=new WvProcess();
		List<Map<String,Object>> listWvProcess=null;
		uuidList.clear();
		for(int i=0;i<5;i++){
			cnd.reset();
			wvProcess.setUploadStatus(EWvProcess.uploadStatus_1.getKey());
			cnd.andEquals("uploadStatus");
			cnd.append(" or (upload_Status=2 and process_Uuid not in (select work_uuid from WV_UPLOAD_TASK_INFO where Task_Type=4))");
			wvProcess.setJhCnd(cnd);
			wvProcess.setPage(page);
			listWvProcess=this.wvProcessService.queryMapListById(wvProcess, "queryMapListToProcessUuid");
			if(listWvProcess!=null&&listWvProcess.size()>0){
				//A:保存任务信息
				 for(Map<String,Object> map:listWvProcess){
					 uuidList.add(map.get("processUuid").toString());
					 wvUploadTaskInfo=new WvUploadTaskInfo();
					 wvUploadTaskInfo.setTaskUuid(model.getUUID());
					 wvUploadTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_4.getKey());
					 wvUploadTaskInfo.setCreateTime(new Date());
					 wvUploadTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_4.getKey());
					 wvUploadTaskInfo.setWorkUuid(map.get("processUuid").toString());
					 this.wvUploadTaskInfoService.add(wvUploadTaskInfo);
				 }
				 wvProcess.setStrList(uuidList);
				 cnd.reset();
				 cnd.andIn("processUuid", "strList", uuidList);
				 JhUpdate jhUpdate=new JhUpdate();
				 jhUpdate.add("uploadStatus");
				 wvProcess.setUploadStatus(EWvProcess.uploadStatus_2.getKey());
				 wvProcess.setJhCnd(cnd);
				 wvProcess.setJhUpdate(jhUpdate);
				 this.wvProcessService.updateSame(wvProcess);
				 uuidList.clear();
			}else{
				 break;
			}
	    }
		
		
		//第三步： 查询环节对应产品任务
		WvProduct wvProduct=new WvProduct();
		List<Map<String,Object>> listWvProduct=null;
		uuidList.clear();
		for(int i=0;i<5;i++){
			cnd.reset();
			wvProduct.setUploadStatus(EWvProduct.uploadStatus_1.getKey());
			cnd.andEquals("uploadStatus");
			cnd.append(" or (upload_Status=2 and product_uuid not in (select work_uuid from WV_UPLOAD_TASK_INFO where task_type=5)) ");
			wvProduct.setJhCnd(cnd);
			wvProduct.setPage(page);
			listWvProduct=this.wvProductService.queryMapListById(wvProduct, "queryMapListToProductUuid");
			if(listWvProduct!=null&&listWvProduct.size()>0){
				//A:保存任务信息
				 for(Map<String,Object> map:listWvProduct){
					 uuidList.add(map.get("productUuid").toString());
					 wvUploadTaskInfo=new WvUploadTaskInfo();
					 wvUploadTaskInfo.setTaskUuid(model.getUUID());
					 wvUploadTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_5.getKey());
					 wvUploadTaskInfo.setCreateTime(new Date());
					 wvUploadTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_5.getKey());
					 wvUploadTaskInfo.setWorkUuid(map.get("productUuid").toString());
					 this.wvUploadTaskInfoService.add(wvUploadTaskInfo);
				 }
				 wvProduct.setStrList(uuidList);
				 cnd.reset();
				 cnd.andIn("productUuid", "strList", uuidList);
				 JhUpdate jhUpdate=new JhUpdate();
				 jhUpdate.add("uploadStatus");
				 wvProduct.setUploadStatus(EWvProduct.uploadStatus_2.getKey());
				 wvProduct.setJhCnd(cnd);
				 wvProduct.setJhUpdate(jhUpdate);
				 this.wvProductService.updateSame(wvProduct);
				 uuidList.clear();
			}else{
				 break;
			}
	    }
	}
	
	public void updateCloudCameraAndFlowConfigTaskInfo(){
		List<Integer> taskTypeList=new ArrayList<Integer>();
		List<String> taskUuidList=new ArrayList<String>();
		taskTypeList.add(EWvUploadTaskInfo.taskType_1.getKey());
		taskTypeList.add(EWvUploadTaskInfo.taskType_2.getKey());
		WvUploadTaskInfo wvUploadTaskInfo=new WvUploadTaskInfo();
		JhCnd cnd=new JhCnd();
		cnd.andIn("taskType", "intList", taskTypeList);
		wvUploadTaskInfo.setIntList(taskTypeList);
		wvUploadTaskInfo.setJhCnd(cnd);
		List<Map<String,Object>> list=this.wvUploadTaskInfoService.queryMapListById(wvUploadTaskInfo,"queryMapList");
		for(Map<String,Object> tempMap:list){
			if(Integer.parseInt(tempMap.get("taskType").toString())==EWvUploadTaskInfo.taskType_1.getKey()){
				this.wvPublicSynchronousService.updateSynchronousCamera();
				taskUuidList.add(tempMap.get("taskUuid").toString());
			}else if(Integer.parseInt(tempMap.get("taskType").toString())==EWvUploadTaskInfo.taskType_2.getKey()){
				this.wvPublicSynchronousService.updateSynchronousFlow();
				taskUuidList.add(tempMap.get("taskUuid").toString());
			}
		}
		//清除任务信息
		if(taskUuidList.size()>0){
			cnd.reset();
			cnd.andIn("taskUuid", "strList", taskUuidList);
			wvUploadTaskInfo.setStrList(taskUuidList);
			wvUploadTaskInfo.setJhCnd(cnd);
			this.wvUploadTaskInfoService.deleteSame(wvUploadTaskInfo);
			taskUuidList.clear();
		}
		taskTypeList.clear();
		if(list!=null&&list.size()>0){
			list.clear();
		}
		list=null;
	}
	
	@Override
	public void updateCloudFileTaskInfo() {
		WvFlow wvFlow=new WvFlow();
		JhCnd cnd=new JhCnd();
		wvFlow.setStatus(EWvFlow.status_1.getKey());
		cnd.andEquals("status");
		wvFlow.setJhCnd(cnd);
		List<WvFlow> listWvFlow=this.wvFlowService.queryModelList(wvFlow);
		List<String> codeList=new ArrayList<String>();
		for(WvFlow tempWvFlow:listWvFlow){
			//获取配置信息
			WvAutoUploadCloudConfig wvAutoUploadCloudConfig=new WvAutoUploadCloudConfig();
			cnd.reset();
			wvAutoUploadCloudConfig.setFlowUuid(tempWvFlow.getFlowUuid());
			cnd.andEquals("flowUuid");
			wvAutoUploadCloudConfig.setJhCnd(cnd);
			List<WvAutoUploadCloudConfig> listConfig=this.wvAutoUploadCloudConfigService.queryModelList(wvAutoUploadCloudConfig);
			if(listConfig==null&&listConfig.size()<=0){
				//throw new JingHaoCustomerException(EJhTwsCode.TWS8001.getCode(),"请配置视频自动上传配置信息！！");
				this.logger.info("请配置视频自动上传配置信息！！");
				continue;
			}
			codeList.clear();
			Set<String> dateSet=new HashSet<String>();
			for(WvAutoUploadCloudConfig tempCloudConfig:listConfig){
				dateSet.add(tempCloudConfig.getProcessCode());
				codeList.add(tempCloudConfig.getProcessCode());
			}
			List<String> uuidList=new ArrayList<String>();
			JhUpdate jhUpdate=null;
			WvUploadTaskInfo wvUploadTaskInfo=null;
			WvTaskInfo  model=new WvTaskInfo();
			//检查是否配置上传功能
			if(dateSet.contains("megerProcess")){
				uuidList.clear();
				//第一步：查询托盘任务
				WvPallet  wvPallet=new  WvPallet();
				List<Map<String,Object>> listWvPallet=null;
				for(int i=0;i<4;i++){ 
					cnd.reset();
					cnd.andEquals("fileUploadStatus");
					wvPallet.setFileUploadStatus(EWvPallet.fileUploadStatus_1.getKey());
					wvPallet.setFlowCode(tempWvFlow.getCode());
					wvPallet.setJhCnd(cnd);
					listWvPallet=this.wvPalletService.queryMapListById(wvPallet, "queryMapListToPalletUuid");
					if(listWvPallet!=null&&listWvPallet.size()>0){
						//A:保存任务信息
						for(Map<String,Object> map:listWvPallet){
							uuidList.add(map.get("palletUuid").toString());
							wvUploadTaskInfo=new WvUploadTaskInfo();
							wvUploadTaskInfo.setTaskUuid(model.getUUID());
							wvUploadTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_7.getKey());
							wvUploadTaskInfo.setCreateTime(new Date());
							wvUploadTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_7.getKey());
							wvUploadTaskInfo.setWorkUuid(map.get("palletUuid").toString());
							this.wvUploadTaskInfoService.add(wvUploadTaskInfo);
						}
						wvPallet.setStrList(uuidList);
						cnd.reset();
						cnd.andIn("palletUuid", "strList", uuidList);
						jhUpdate=new JhUpdate();
						jhUpdate.add("fileUploadStatus");
						wvPallet.setFileUploadStatus(EWvProcess.fileUploadStatus_2.getKey());
						wvPallet.setJhCnd(cnd);
						wvPallet.setJhUpdate(jhUpdate);
						this.wvPalletService.updateSame(wvPallet);
					}else{
						break;
					}
				}
			}
			
			//第二步：查询环节信息任务
			WvProcess wvProcess=new WvProcess();
			List<Map<String,Object>> listWvProcess=null;
			uuidList.clear();
			for(int i=0;i<4;i++){
				cnd.reset();
				cnd.andEquals("fileUploadStatus");
				cnd.andIn("fprocessId", "strList", codeList);
				cnd.append(" and fpallet_Id in (select pallet_id from WV_PALLET f where f.flow_code='"+tempWvFlow.getCode()+"')");
				wvProcess.setStrList(codeList);
				wvProcess.setFileUploadStatus(EWvProcess.fileUploadStatus_1.getKey());
				wvProcess.setJhCnd(cnd);
				listWvProcess=this.wvProcessService.queryMapListById(wvProcess, "queryMapListToProcessUuid");
				if(listWvProcess!=null&&listWvProcess.size()>0){
					//A:保存任务信息
					 for(Map<String,Object> map:listWvProcess){
						 uuidList.add(map.get("processUuid").toString());
						 wvUploadTaskInfo=new WvUploadTaskInfo();
						 wvUploadTaskInfo.setTaskUuid(model.getUUID());
						 wvUploadTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_6.getKey());
						 wvUploadTaskInfo.setCreateTime(new Date());
						 wvUploadTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_6.getKey());
						 wvUploadTaskInfo.setWorkUuid(map.get("processUuid").toString());
						 this.wvUploadTaskInfoService.add(wvUploadTaskInfo);
					 }
					 wvProcess.setStrList(uuidList);
					 cnd.reset();
					 cnd.andIn("processUuid", "strList", uuidList);
					 jhUpdate=new JhUpdate();
					 jhUpdate.add("fileUploadStatus");
					 wvProcess.setFileUploadStatus(EWvProcess.fileUploadStatus_2.getKey());
					 wvProcess.setJhCnd(cnd);
					 wvProcess.setJhUpdate(jhUpdate);
					 this.wvProcessService.updateSame(wvProcess);
				}else{
					 break;
				}
		    }
			
			//检查是否配置上传功能
			if(dateSet.contains("megerProcess")){
				//第三步： 查询环节对应产品任务
				cnd.reset();
				WvProduct wvProduct=new WvProduct();
				List<Map<String,Object>> listWvProduct=null;
				uuidList.clear();
				for(int i=0;i<4;i++){
					cnd.reset();
					cnd.andEquals("fileUploadStatus");
					wvProduct.setFileUploadStatus(EWvProduct.fileUploadStatus_1.getKey());
					wvProduct.setJhCnd(cnd);
					listWvProduct=this.wvProductService.queryMapListById(wvProduct, "queryMapListToProductUuid");
					if(listWvProduct!=null&&listWvProduct.size()>0){
						//A:保存任务信息
						 for(Map<String,Object> map:listWvProduct){
							 uuidList.add(map.get("productUuid").toString());
							 wvUploadTaskInfo=new WvUploadTaskInfo();
							 wvUploadTaskInfo.setTaskUuid(model.getUUID());
							 wvUploadTaskInfo.setTaskType(EWvUploadTaskInfo.taskType_8.getKey());
							 wvUploadTaskInfo.setCreateTime(new Date());
							 wvUploadTaskInfo.setTaskLevel(EWvUploadTaskInfo.taskType_8.getKey());
							 wvUploadTaskInfo.setWorkUuid(map.get("productUuid").toString());
							 this.wvUploadTaskInfoService.add(wvUploadTaskInfo);
						 }
						 wvProduct.setStrList(uuidList);
						 cnd.reset();
						 cnd.andIn("productUuid", "strList", uuidList);
						 jhUpdate=new JhUpdate();
						 jhUpdate.add("fileUploadStatus");
						 wvProduct.setFileUploadStatus(EWvProduct.fileUploadStatus_2.getKey());
						 wvProduct.setJhCnd(cnd);
						 wvProduct.setJhUpdate(jhUpdate);
						 this.wvProductService.updateSame(wvProduct);
					}else{
						 break;
					}
			    }
			}

		}

	}
	//==================定制内容结束======================
	public static void main(String[] args) {
		Integer a = 9;
		System.out.println(a.equals(EWvTaskInfo.videoStatus_9.getKey()));
	}
}
